import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../../../services/address.dart';
import '../../../../services/dio_manager.dart';
import '../../login_view.dart';

class RegisterSetPassWordController extends GetxController{

  var tf1 = TextEditingController();
  var tf2 = TextEditingController();


  var showps1 = true;
  var showps2 = true;




  /// 设置用户名密码请求
  requestDataWithSetPassword(var mobile,var password,var code)async{

    var params = {
      'account_type':'0',
      'user_type':'0',
      'login':mobile.replaceAll(new RegExp(r"\s+\b|\b\s"), ""),
      // 'name':'',
      'mobile':mobile.replaceAll(new RegExp(r"\s+\b|\b\s"), ""),
      'email':'',
      'password':password,
      'code':code,
      'company_name':'',
    };

    var json = await DioManager().kkRequest(Address.signup,bodyParams: params,isShowLoad: true);

    if(json['errmsg']=='ok'){
      BotToast.showText(text: json['message']);
      Get.offAll(LoginView());
    }else{
      // Get.offAll(LoginView());
    }


  }

  /// 显示密码
  tapClickShowPassWord1(){
    showps1=!showps1;
    update();
  }


  /// 显示密码
  tapClickShowPassWord2(){
    showps2=!showps2;
    update();
  }

  /// 点击确定
  tapClickEnter(var phone,var verifyCode){
    if(tf1.text.isEmpty){
      // Toast.toast(Get.overlayContext,msg: '请输入密码');
      BotToast.showText(text: '请输入密码');
      return;
    }
    if(tf1.text!=tf2.text){
      // Toast.toast(Get.overlayContext,msg: '请输入密码');
      BotToast.showText(text: '两次密码不一样');
      return;
    }

    requestDataWithSetPassword(phone, tf1.text, verifyCode);
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

}